package com.ruoyi.web.controller.help;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.help.domain.HelpWalkthrough;
import com.ruoyi.help.service.IHelpWalkthroughService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 培训记录Controller
 * 
 * @author ruoyi
 * @date 2023-06-13
 */
@RestController
@RequestMapping("/help/walkthrough")
public class HelpWalkthroughController extends BaseController
{
    @Autowired
    private IHelpWalkthroughService helpWalkthroughService;

    /**
     * 查询培训记录列表
     */
    @PreAuthorize("@ss.hasPermi('help:walkthrough:list')")
    @GetMapping("/list")
    public TableDataInfo list(HelpWalkthrough helpWalkthrough)
    {
        startPage();
        List<HelpWalkthrough> list = helpWalkthroughService.selectHelpWalkthroughList(helpWalkthrough);
        return getDataTable(list);
    }

    /**
     * 导出培训记录列表
     */
    @PreAuthorize("@ss.hasPermi('help:walkthrough:export')")
    @Log(title = "培训记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HelpWalkthrough helpWalkthrough)
    {
        List<HelpWalkthrough> list = helpWalkthroughService.selectHelpWalkthroughList(helpWalkthrough);
        ExcelUtil<HelpWalkthrough> util = new ExcelUtil<HelpWalkthrough>(HelpWalkthrough.class);
        util.exportExcel(response, list, "培训记录数据");
    }

    /**
     * 获取培训记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('help:walkthrough:query')")
    @GetMapping(value = "/{uId}")
    public AjaxResult getInfo(@PathVariable("uId") Long uId)
    {
        return success(helpWalkthroughService.selectHelpWalkthroughByUId(uId));
    }

    /**
     * 新增培训记录
     */
    @PreAuthorize("@ss.hasPermi('help:walkthrough:add')")
    @Log(title = "培训记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HelpWalkthrough helpWalkthrough)
    {
        return toAjax(helpWalkthroughService.insertHelpWalkthrough(helpWalkthrough));
    }

    /**
     * 修改培训记录
     */
    @PreAuthorize("@ss.hasPermi('help:walkthrough:edit')")
    @Log(title = "培训记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HelpWalkthrough helpWalkthrough)
    {
        return toAjax(helpWalkthroughService.updateHelpWalkthrough(helpWalkthrough));
    }

    /**
     * 删除培训记录
     */
    @PreAuthorize("@ss.hasPermi('help:walkthrough:remove')")
    @Log(title = "培训记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uIds}")
    public AjaxResult remove(@PathVariable Long[] uIds)
    {
        return toAjax(helpWalkthroughService.deleteHelpWalkthroughByUIds(uIds));
    }
}
